/**
 * 
 */
package net.kaizhong.j2ee01.filter;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * @author kzuser
 *
 */
public class HelloWorldFilter implements Filter
{
    private static final Logger logger = LogManager.getLogger(HelloWorldFilter.class);

    FilterConfig filterConfig = null;

    public HelloWorldFilter()
    {
        logger.info("开始执行构造函数 HelloWorldFilter()");
        logger.info("结束执行构造函数 HelloWorldFilter()");
    }

    @Override
    public void destroy()
    {
        logger.info("开始执行过滤器销毁 HelloWorldFilter.destroy()");
        logger.info("结束执行过滤器销毁  HelloWorldFilter.destroy()");
    }

    @Override
    public void doFilter(ServletRequest paramServletRequest, ServletResponse paramServletResponse,
            FilterChain paramFilterChain) throws IOException, ServletException
    {
        logger.info("开始执行过滤器修改请求或响应 HelloWorldFilter.doFilter()");
        paramFilterChain.doFilter(paramServletRequest, paramServletResponse);
        logger.info("结束执行过滤器修改请求或响应 HelloWorldFilter.doFilter()");
    }

    @Override
    public void init(FilterConfig paramFilterConfig) throws ServletException
    {
        logger.info("开始执行过滤器初始化 HelloWorldFilter.init()");
        this.filterConfig = paramFilterConfig;

        Enumeration<String> paras = paramFilterConfig.getInitParameterNames();

        while (paras.hasMoreElements())
        {
            String paraName = paras.nextElement();
            String val = paramFilterConfig.getInitParameter(paraName);
            logger.info(String.format("paraName=%s,paraValue=%s", paraName, val));

        }

        logger.info("结束执行过滤器初始化 HelloWorldFilter.init()");
    }

}
